package com.kaizzi.data.jdl.helper;

import com.kaizzi.data.common.utils.JsonUtil;
import com.kaizzi.data.jdl.model.CommentsModel;
import com.kaizzi.data.jdl.model.ExcelModel;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kzen
 * @Description page4 data
 * @date 2020/9/10
 */
@Component
public class PageData4 {

    public String getData(ExcelModel model){
        List<CommentsModel> comments = model.getComments();
        Page page = new Page();
        for (CommentsModel comment:comments) {
            if (comment.getPage().equals("P4")){
                if (comment.getName().equals("Summary")){
                    page.setSummary(getChildData(comment));
                }
                if (comment.getName().equals("insights")){
                    page.setInsights(getChildData(comment));
                }
                if (comment.getName().equals("Action Plan")){
                    page.setActionPlan(getChildData(comment));
                }
            }
        }
        return JsonUtil.serialize(page);
    }

    /**
     * @param model 行数据
     * @return 集合数据 去空
     */
    private static List<String> getChildData(CommentsModel model){
        String data = model.getData();
        String[] split = data.split("\n");
        List<String> list = new ArrayList<>();
        for (String temp:split) {
            if (temp.equals("")){
                continue;
            }
            list.add(temp);
        }
        return list;
    }

    @Data
    private static class Page {
        private List<String> actionPlan;
        private List<String> summary;
        private List<String> insights;
    }

}
